<{include file="header.html"}>

<script type="text/javascript">

	function validate()
	{
		// validate IMAGE
		// - IMAGE must be not empty
		// - the extension must is 'png','jpg','jpeg','gif', or 'bmp'
		<{if $product_image->ID}>
		if ($('#IMAGE').val() != '' && !validateExtension($('#IMAGE').val(), new Array('png','jpg','jpeg','gif','bmp'))) {
			showErrorBubble($('#IMAGE'), '<{$smarty.const._MSG_IMAGE_EXTENSION_IS_INVALID|utf8_escape_js}>');
			return false;
		}
		<{else}>
		if (!$('#IMAGE').val() || $('#IMAGE').val() == '' || !validateExtension($('#IMAGE').val(), new Array('png','jpg','jpeg','gif','bmp'))) {
			showErrorBubble($('#IMAGE'), '<{$smarty.const._MSG_IMAGE_EXTENSION_IS_INVALID|utf8_escape_js}>');
			return false;
		}
		<{/if}>

		document.user_form.submit();
	}

	function validateExtension(fileName, extension)
	{
		var fileExtension = getFileExtension(fileName).toLowerCase();
		if ($.isArray(extension)) {
			for(var i = 0; i < extension.length; i++) {
				if (fileExtension == extension[i].toLowerCase()) {
					return true;
				}
			}
		} else {
			return (fileExtension == extension.toLowerCase());
		}

		return false;
	}

	function getFileExtension(fileName)
	{
		var found = fileName.lastIndexOf('.') + 1;
		return (found > 0 ? fileName.substr(found) : "");
	}
</script>

		<div class="box_two_third">
			<div class="box_head"><{$smarty.const._LB_PRODUCT_MANAGEMENT|utf8_escape_html}></div>
			<div class="box_content">

				<form enctype="multipart/form-data" action="<{$smarty.server.REQUEST_URI}>" method="post" name="user_form">
				<input type="hidden" id="ID" value="<{$product_image->ID}>"/>
				<input type="hidden" id="act" name="act" value="<{$smarty.const.ACT_VALID_EDIT}>"/>
				<table>
                   <tr>
						<td><{$smarty.const._LB_IMAGE|utf8_escape_html}>&nbsp;:&nbsp;<{$smarty.const._LB_REQUIRE_FIELD}></td>
						<td colspan="3">
							<{if $product_image->IMAGE}>
								<img width="180" height="150" style="display: block; opacity: 1; width: 180px; height: 150px; cursor: pointer;" src="<{$smarty.const.PRODUCT_IMAGE_URL}>/<{$product_image->IMAGE}>">
								<br/>
							<{/if}>
							<input name="IMAGE" id="IMAGE" type="file"/>
                        </td>
					</tr>
                    <tr>
						<td><{$smarty.const._LB_DISABLED|utf8_escape_html}>&nbsp;:&nbsp;</td>
						<td colspan="3"><input type="checkbox" value="1" name="DISABLED" <{if $product_image->DISABLED}>checked<{/if}>/></td>
					</tr>
					<tr>
						<td class="submit" colspan="4" style="padding-top:10px"><br />
							<a class="tribullet" href="<{$backlink}>"><{$smarty.const._LB_BACK}></a>
							<a class="tribullet" href="#" onclick="validate()"><{$smarty.const._LB_VALIDATE}></a>
						</td>
					</tr>
				</table>
				</form>
			</div>
		</div>
<{include file="footer.html"}>
